package cn.swust.action;

import java.util.Map;

import org.apache.struts2.ServletActionContext;

import cn.swust.javaMail.MailSenderInfo;
import cn.swust.javaMail.SimpleMailSender;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AdminAction  extends ActionSupport{
	public String adminLogin()
	{
		String meta = "";
		String adminName = ServletActionContext.getRequest().getParameter("adminName");
		String	adminPassword = ServletActionContext.getRequest().getParameter("adminPassword");
		String  loginCode = ServletActionContext.getRequest().getParameter("loginCode");
		Map<String, Object> sesstion = ActionContext.getContext().getSession();
		String code = (String)sesstion.get("random");
/*		if(!loginCode.equalsIgnoreCase(code))
		{
			ActionContext.getContext().getSession().remove("random");
			if(loginCode=="")
				sesstion.put("message", "验证码不能为空！");
		   else
			sesstion.put("message", "你输入的验证码错误!");
			return "input";
		}*/
		if(adminName.equals("admin")&&adminPassword.equals("admin_swust")){
			sesstion.put("fullName", adminName);
			//发送邮件
		     MailSenderInfo mailInfo = new MailSenderInfo();   	     
		     mailInfo.setToAddress("491404155@qq.com");   
		     mailInfo.setSubject("欢迎你的登录！");   
		     mailInfo.setContent("孙凉菜！！！！！");   
		        //这个类主要来发送邮件  
		     SimpleMailSender.sendByAsychMail(mailInfo);
			return SUCCESS;
		}
		return "input";
	}
	public String loginOut()
	{
		ActionContext.getContext().getSession().clear();
		ActionContext.getContext().getSession().put("message","提示：");
		return SUCCESS;
	}
}
